
//https://leetcode.cn/problems/search-insert-position/
int searchInsert(int* nums, int numsSize, int target) {
    int begin = 0;
    int end = numsSize - 1;

    while (begin <= end)
    {
        int mid = (begin + end) / 2;
        if (nums[mid] < target)
        {
            begin = mid + 1;
        }
        else if (nums[mid] > target)
        {
            end = mid - 1;
        }
        else if (nums[mid] == target)
        {
            return mid;
        }
    }
    return begin;
}